package com.ruoyi.result.horizontalProjects.mapper;

import java.util.List;
import java.util.Map;

import com.ruoyi.result.horizontalProjects.domain.ResultHorizontalProjects;
import com.ruoyi.result.horizontalProjects.domain.dto.ResultHorizontalProjectsDTO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 横向课题Mapper接口
 *
 * @author ruoyi
 * @date 2025-01-22
 */
@Mapper
public interface ResultHorizontalProjectsMapper
{
    /**
     * 查询横向课题
     *
     * @param id 横向课题主键
     * @return 横向课题
     */
    public ResultHorizontalProjects selectResultHorizontalProjectsById(Long id);

    /**
     * 查询横向课题列表
     *
     * @param resultHorizontalProjects 横向课题
     * @return 横向课题集合
     */
    public List<ResultHorizontalProjects> selectResultHorizontalProjectsList(ResultHorizontalProjectsDTO resultHorizontalProjects);

    /**
     * 新增横向课题
     *
     * @param resultHorizontalProjects 横向课题
     * @return 结果
     */
    public int insertResultHorizontalProjects(ResultHorizontalProjects resultHorizontalProjects);

    /**
     * 修改横向课题
     *
     * @param resultHorizontalProjects 横向课题
     * @return 结果
     */
    public int updateResultHorizontalProjects(ResultHorizontalProjects resultHorizontalProjects);

    /**
     * 删除横向课题
     *
     * @param id 横向课题主键
     * @return 结果
     */
    public int deleteResultHorizontalProjectsById(Long id);

    /**
     * 批量删除横向课题
     *
     * @param ids 需要删除的数据主键集合
     * @return 结果
     */
    public int deleteResultHorizontalProjectsByIds(Long[] ids);

    List<ResultHorizontalProjects> selectResultHorizontalProjectsByIds(Long[] ids);

    @Select("SELECT COUNT(*) FROM result_horizontal_projects WHERE sync_status = '是' AND is_deleted = 0")
    long selectCount();

    @Select("SELECT YEAR(start_time) as year, COUNT(*) as count FROM result_horizontal_projects " +
            "WHERE is_deleted = 0 " +
            "GROUP BY YEAR(start_time) " +
            "ORDER BY year")
    List<Map<String, Object>> countByYear();

    @Select("SELECT YEAR(start_time) as year, COUNT(*) as count FROM result_horizontal_projects " +
            "WHERE is_deleted = 0 AND user_id = #{userId} " +
            "GROUP BY YEAR(start_time) " +
            "ORDER BY year")
    List<Map<String, Object>> countByYearAndUserId(@Param("userId") Long userId);
}
